import 'package:earclean/app/modules/widget/mang_dialog.dart';
import 'package:earclean/app/modules/widget/pay_dialog.dart';
import 'package:earclean/app/request/http_request.dart';
import 'package:earclean/app/routes/app_pages.dart';
import 'package:earclean/app/util/Yue_utils.dart';
import 'package:earclean/app/util/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class ServeController extends GetxController {
  final dataList = [].obs;
  final list = [].obs;
  final index = 0.obs;
  @override
  void onInit() {
    super.onInit();
  }

  @override
  void onReady() {
    loadData();
    super.onReady();
  }

  @override
  void onClose() {}

  clickItem(idx) {
    if (idx != index) {
      index.value = idx;
      list.value = dataList[idx]['list'] ?? [];
    }
  }

  loadData() async {
    final result = await HttpRequest.get('https://iamz.jiliol.net/health.json');
    if (result.result) {
      List map = result.data ?? [];
      if (map.isNotEmpty) {
        dataList.value = map;
        list.value = dataList[0]['list'] ?? [];
        // bannerList.value = map[0]['list'] ?? [];
        // tuijianList.value = map[1]['list'] ?? [];
        // shushiList.value = map[2]['list'] ?? [];
      }
    }
  }

  toServeInfo(Map item) {
    Get.toNamed(Routes.SERVEINFO, arguments: item);
  }

  // 预约
  toYue(Map item) {
    YueUtils.yuyue({
      'id': item['id'],
      'title': item['projectName'],
      'pic': item['projectPic'],
      'timer': item['projectTimer'],
      'price': item['projectPrice'],
    });
  }
}
